"""
登录-》新增用户分组-
使用requests+pytest+allure
"""
import requests
import pytest
import allure
from random import randint
url = "http://121.40.86.4:8899"  # 全局的地址
@allure.feature("用户分组流程")
class TestGroup: # 测试类
    @pytest.fixture()  # 定义了一个夹具，级别为：class，自动执行
    def login(self):   # 发起登录的请求
        response = requests.post(url = url+"/adminapi/login",json={"account":"admin","pwd":"Aa010903!","key":"6826e235c33f1","captchaType":"blockPuzzle","captchaVerification":""})
        self.token = response.json()['data']['token']   # 提取token
        assert response.status_code == 200  # 断言接口请求是否成功
        yield self.token
    @allure.story("新增用户分组")
    def test_add_group(self,login):  # 新增用户分组
        random_int = randint(1,999)   # 随机数
        response = requests.post(url = url+"/adminapi/user/user_group/save.html",json={"group_name":"test"+str(random_int)},headers={"Authori-zation":"Bearer "+str(login)})
        assert response.status_code == 200
# pytest <py文件> --alluredir=allure   # 生成allure  数据
# allure generate ./allure/ -o ./reports --clean  #  生成allure报告到reports文件夹里



